home *** CD-ROM | disk | FTP | other *** search
- ; FILE: upd32.asm
- ; DATE: 910917:1711
- ; LMOD: 911112:1637
- ; FOR: calculate crc-32 of buffer contents
- ;
- TITLE UPD32 - crc calculation
- comment #
- DYNAMICRO CONSULTING LIMITED, 1991
- """"""""""""""""""""""""""""""""""
- This module implements 32-bit cyclic redundancy
- checksum calculation. Routine _upd32 is
- called with the checksum and byte pointer and
- length of string to calculate on the stack,
- and returns with the new checksum in bx&dx:ax
- (bx:ax for MSC, dx:ax for ECO)
- #
- ; segment and group definitions
- include amodel.inc
- if ECO ; Ecosoft C 4.13
- include \eco\headers\pro.h
- $d$dataseg segment public 'data2'
- endif
- if MSC ; Microsoft C 6.00
- .DATA
- endif
-
- ; the following tables were produced by program
- ; mkcrc32.c (listing 3). Since you can obtain
- ; them in full by running that program, we're
- ; omitting most of them here to save listing space.
-
- ; crc tables: CRC-32, polynomial 04c11db7
-
- crct0 db 000h,004h,009h,00dh ; 00-03
- db 013h,017h,01ah,01eh ; 04-07
- db 026h,022h,02fh,02bh ; 08-0b
- ; ...
- db 0afh,0abh,0a6h,0a2h ; f8-fb
- db 0bch,0b8h,0b5h,0b1h ; fc-ff
-
- crct1 db 000h,0c1h,082h,043h ; 00-03
- db 004h,0c5h,086h,047h ; 04-07
- db 008h,0c9h,08ah,04bh ; 08-0b
- ; ...
- db 0b0h,071h,032h,0f3h ; f8-fb
- db 0b4h,075h,036h,0f7h ; fc-ff
-
- crct2 db 000h,01dh,03bh,026h ; 00-03
- db 076h,06bh,04dh,050h ; 04-07
- db 0edh,0f0h,0d6h,0cbh ; 08-0b
- ; ...
- db 010h,00dh,02bh,036h ; f8-fb
- db 066h,07bh,05dh,040h ; fc-ff
-
- crct3 db 000h,0b7h,06eh,0d9h ; 00-03
- db 0dch,06bh,0b2h,005h ; 04-07
- db 0b8h,00fh,0d6h,061h ; 08-0b
- ; ...
- db 0b1h,006h,0dfh,068h ; f8-fb
- db 06dh,0dah,003h,0b4h ; fc-ff
-
- if ECO
- $d$dataseg ends
- endif
- page
- public _upd32
- if ECO
- if BIGCODE
- $c$_upd32 segment word public 'code'
- else
- $b$prog segment public 'code'
- endif
- endif
- if MSC
- .CODE
- endif
- ; int upd32(long crc,char *buf,int len) {
- ; /*
- _upd32 proc
- push bp
- mov bp,sp
- push si
- push di
- if BIGDATA
- push ds
- push es
- mov ax,seg DGROUP
- mov ds,ax
- mov ax,[bp][6+PARMLOC] ; buf,seg
- mov es,ax
- endif
- mov ax,[bp][PARMLOC] ; crc,low
- mov dx,[bp][2+PARMLOC] ; crc,hi
- mov si,[bp][4+PARMLOC] ; buf,ofs
- if BIGDATA
- mov cx,[bp][8+PARMLOC] ; len
- else
- mov cx,[bp][6+PARMLOC] ; len
- endif
- updl:
- ; do { c code is presented in comments
- ; get the next byte to process
- mov di,ax ; crc,low
- if BIGDATA
- mov al,es:[si] ; byte
- inc si
- else
- lodsb ; byte
- endif
-
- ; p=crct0+(al^((crc>>24)&0xff);
- mov bx,offset DGROUP:crct0 ; table
- ; xor byte with high 8 bits of old crc
- xor al,dh
- ; add to crct0 base addr
- xor ah,ah
- add bx,ax ; bx is p
- mov ax,di ; crc,low
-
- ; crc=((*p^((crc>>16)&0xff))<<24)+
- ; ((*(p+256)^((crc>>8)&0xff))<<16)+
- ; ((*(p+512)^(crc&0xff))<<8)+*(p+768);
- xor dl,[bx] ; *p ^ old crc's 3rd byte
- mov dh,dl ; to msb
- inc bh ; p+256
- xor ah,[bx] ; xor old crc's 2nd byte
- mov dl,ah ; put in 3rd
- inc bh ; p+512
- xor al,[bx] ; xor old crc's lsb
- mov ah,al ; to second byte
- inc bh ; p+768
- mov al,[bx] ; add *(p+768)
- ; hand compilation has its advantages!!!
-
- ; } while (--len);
- loop updl
-
- mov bx,dx ; copy crc hi to bx
- if BIGDATA
- pop es
- pop ds
- endif
- pop di
- pop si
- pop bp
- ret ; new crc in dx/bx:ax
- _upd32 endp
-
- if ECO
- if BIGCODE
- $c$_upd32 ends
- else
- $b$prog ends
- endif
- endif
- end
- ; */ }
-